# Contributor: Bart Ribbers <bribbers@disroot.org>
# Maintainer: Bart Ribbers <bribbers@disroot.org>
pkgname=py3-spsdk
pkgver=2.1.1
pkgrel=1
pkgdesc="Open Source Secure Provisioning SDK for NXP MCU/MPU"
url="https://github.com/NXPmicro/spsdk"
# s390x, ppc64le and riscv64 blocked by py3-cmsis-pack-manager, 32 bit issues with py3-libusbsio
arch="x86_64 aarch64"
license="BSD-3-Clause"
depends="
	pcsc-lite-libs
	py3-asn1crypto
	py3-astunparse
	py3-bincopy
	py3-bitstring
	py3-click
	py3-click-command-tree
	py3-click-option-group
	py3-cmsis-pack-manager
	py3-colorama
	py3-commentjson
	py3-crcmod
	py3-cryptography
	py3-deepmerge
	py3-fastjsonschema
	py3-hexdump
	py3-jinja2
	py3-libusbsio
	py3-oscrypto
	py3-platformdirs
	py3-pycryptodome
	py3-pylink-square
	py3-pyocd
	py3-pyscard
	py3-pyserial
	py3-requests<2.32
	py3-ruamel.yaml
	py3-sly
	py3-typing-extensions
	python3
	"
makedepends="
	py3-gpep517
	py3-installer
	py3-setuptools
	py3-wheel
	"
checkdepends="
	py3-attrs
	py3-pytest
	py3-pytest-cov
	py3-pytest-xdist
	py3-voluptuous
	"
subpackages="$pkgname-pyc spsdk:_spsdk"
source="spsdk-$pkgver.tar.gz::https://github.com/NXPmicro/spsdk/archive/refs/tags/$pkgver.tar.gz
	0001-Remove-pypemicro.patch
	0002-Add-missing-test-file.patch
	0003-Fix-signature-checks.patch
	"
builddir="$srcdir/spsdk-$pkgver"

build() {
	gpep517 build-wheel \
		--wheel-dir .dist \
		--output-fd 3 3>&1 >&2
}

check() {
	python3 -m venv --clear --without-pip --system-site-packages .testenv
	.testenv/bin/python3 -m installer .dist/*.whl
	.testenv/bin/python3 -m pytest \
	--ignore=tests/mcu_examples/test_jupyter.py  \
	-k 'not test_keys_generation_ec and not test_key_types and not test_matching_keys_ecc'
}

package() {
	python3 -m installer -d "$pkgdir" \
		.dist/*.whl
}

_spsdk() {
	depends="$pkgname=$pkgver-r$pkgrel"

	amove usr/bin
	amove usr/lib/python*/site-packages/spsdk/apps/*.py
}

sha512sums="
3ef8398eb0f3008b50a0cac7f9491913f6acc70513f50351a0e15fb64af7759c18f1771a9ca0d297f7977df20e4278072c1b8f70613d1af5d962ab2b0c54f2e6  spsdk-2.1.1.tar.gz
139f2b2f37228c2dfde422f2b6868e1c2654b7a4c4f6c611493835efc8f70bf94096d735dffebcde1ef93bdc60dffd484b27505e275ec3a57499f54b8e938f4d  0001-Remove-pypemicro.patch
14f180df4c8b7d8963f0ccec5c85dbf89bf981e3eb4fc08d27f8ca740fe7e860844a1b808aca1912d22cee72d8018f62535d89196fca762c6f8f3a94882d6af7  0002-Add-missing-test-file.patch
72f9326e3cf4f54aec5f985ae3cd5abb2fbada3f17379565b06223a0ab171e58503205b23af613faeab6ddfa7c2872dc0e9f2d659a1ddc63f0f9d815bc67a858  0003-Fix-signature-checks.patch
"
